package com.ailatrieuphu.activity;

import com.ailatrieuphu.CMD;
import com.ailatrieuphu.Message;
import com.ailatrieuphu.MyActivity;
import com.ailatrieuphu.R;
import com.ailatrieuphu.R.id;
import com.ailatrieuphu.R.layout;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class TestServer extends MyActivity{

	public Button btnRoomIn, btnRoomOut; 
	
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		
		setContentView(R.layout.test_server);
		btnRoomIn = (Button) findViewById(R.id.btnRoomIn);
		btnRoomOut = (Button) findViewById(R.id.btnRoomOut);
		btnRoomIn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Message message=new Message(CMD.C_PLAYER_JOIN_TABLE);
				message.writeInt(10);
				connection.sendMessage(message);
			}
		}); 
		btnRoomOut.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

			}
		});
	} 
 
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	public void onBackPressed() {
		finish();
		connection=null;
		startActivity(ActivityLogin.class);
	}

	@Override
	public void loadResources() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void loadScenes() {
		// TODO Auto-generated method stub
		
	} 

	@Override
	public void processMessage(Message message) {
		switch (message.getCMD()) {
		case CMD.S_PLAYER_JOIN_TABLE:
			boolean check=message.readBoolean();
			String mess=message.readString();
			Log.e("Mess: ",mess );
			showToastLong(mess);
			break;
		case CMD.S_LOGIN_EXIST:
			showToast(message.readString());
			finish();
			connection=null;
			startActivity(ActivityLogin.class);
		break;

		default: 
			break;
		}
	}

	@Override
	public void disConnection() {
		
	}
}
